package com.favorite;

public class Solution5_34 {
    public int[] searchRange(int[] nums, int target) {
        int left = binaty(nums, target);
        int right = binaty(nums, target + 1);
        if (left == nums.length || nums[left] != target) return new int[]{-1, -1};
        return new int[]{left, right - 1};
    }

    public int binaty(int[] nums, int target) {
        int i = 0;
        int j = nums.length;
        while (i < j) {
            int mid = (i + j) >> 1;
            if (target <= nums[mid]) j = mid;
            else i = mid + 1;
        }
        return i;
    }
}

